<header class="header navbar bg-white shadow">
  <div class="btn-group tool-button">
    <a class="btn btn-primary navbar-btn" href="/private/sys/menu" data-pjax id="goback"><i class="ti-angle-left"></i> 返回</a>
  </div>
</header>

<div class="content-wrap">
  <div class="wrapper" style="min-height:500px;">
    <section class="panel panel-form">
      <form id="unitAddForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
            action="/private/sys/menu/editDo" method="post">
        <input type="hidden" id="id" name="id" value="<%=obj.id%>">
        <div class="row mb10">
          <div class="col-lg-12">
            <div class="form-group has-feedback">
              <label for="parentId" class="col-sm-2 control-label">上级菜单</label>

              <div class="col-sm-8">
                  <input id="parentId" type="text" class="form-control" placeholder="顶级菜单" disabled
                         value="<%=typeof parentUnit!='undefined'?parentUnit.name:'' %>"/>
                <input type="hidden" name="parentId" value="<%=typeof parentUnit!='undefined'?parentUnit.id:0 %>">
              </div>
            </div>
            <div class="form-group">
              <label for="name" class="col-sm-2 control-label">菜单名称</label>

              <div class="col-sm-8">
                <input type="text" id="name" class="form-control" name="name" value="<%=obj.name%>" data-parsley-required="true"
                       placeholder="单位名称">
              </div>
            </div>
            <div class="form-group">
              <label for="address" class="col-sm-2 control-label">权限标识</label>

              <div class="col-sm-8">
                <input type="text" id="permission" name="permission" value="<%-obj.permission||''%>"  class="form-control" placeholder="权限标识" data-parsley-required="true">

                <p class="help-block no-m">例如：system:sys</p>
              </div>
            </div>
            <div class="form-group">
              <label for="url" class="col-sm-2 control-label">URL</label>

              <div class="col-sm-8">
                <input type="text" id="url" name="url" value="<%-obj.url||''%>" class="form-control" placeholder="URL">
              </div>
            </div>
            <div class="form-group">
              <label for="target" class="col-sm-2 control-label">target</label>
              <div class="col-sm-8">
                <input type="text" id="target" name="target" value="<%-obj.target||''%>" class="form-control" placeholder="data-pjax">
              </div>
            </div>
            <div class="form-group">
              <label for="icon" class="col-sm-2 control-label">图标</label>
              <div class="col-sm-8">
                <input id="icon" type="text" name="icon" value="<%=obj.icon||''%>" class="form-control" placeholder="图标样式">
                <p class="help-block no-m">效果预览：<i id="iconPreview" class="<%if(obj.icon){%><%-obj.icon%><%}else{%>ti-plus<%}%>"></i></p>
              </div>
            </div>

          </div>
        </div>
        <div class="col-lg-3"></div>
        <div class="col-lg-6">
          <div class="form-group text-center">
            <label></label>

            <div>
              <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
            </div>
          </div>
        </div>
      </form>
    </section>

  </div>
</div>
<a class="exit-offscreen"></a>
<script language="JavaScript">
  $(document).ready(function () {
    //图标样式 实时预览
    $("#icon").on("keyup", function(){
      $("#iconPreview").attr("class", $(this).val());
    });
    $('#unitAddForm').ajaxForm({
      dataType: 'json',
      beforeSubmit: function (arr, form, options) {
        form.find("button:submit").button("loading");
      },
      success: function (data, statusText, xhr, form) {
        if (data.code==0) {
          Toast.success(data.msg);
          setTimeout(function () {
            $("#goback").trigger("click");
          }, 1000);
        } else {
          Toast.error(data.msg);
        }
        form.find("button:submit").button("reset");
      }
    });
  });
</script>
